﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    /// <summary>
    /// 发货单与运输单号关系
    /// </summary>
    public partial class TCPGBMOV 
    {
        ITXEXRPT ITXEXRPT;
  
        public TCPGBMOV()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_GBMOV();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwGB = dwMaster;
            if (dwMaster == null)
            {
                PARTIE = ""; 
            }
            else
            {//这里对批号赋值，但是OnPartieChg不进行任何操作，
                PARTIE = dwMaster["GLPARTIE"].ToString();
            }
        }        
        public override void QueryCommand(object sender, System.Windows.RoutedEventArgs e)
        {
             
            ART = txtART.Text.ToString().Trim();
            if (FROMDATE == "")
            {
                MessageBox.Show("请选择开始日期！");
                return;
            }
            if (ENDDATE == "")
            {
                MessageBox.Show("请选择结束日期！");
                return;
            }
            else
            {
                DAT = Helper.GetDateAddDays(ENDDATE, 1);
            }
            if (ART == "")
            {
                ART = "AAAAAAAAAA";
            }
            if (LO == "")
            {
                MessageBox.Show("请先输入库");
                return;
            }
            if (LB == "")
            {
                MessageBox.Show("请先输入库区");
                return;
            }
            dwData = TBMain.NewRow();
            dwData["ICCLO"] = LO;
            dwData["ICCLB"] = LB;
            dwData["GPSPPART"] = ART;
            dwData["ICCDAT"] = FROMDATE;
            dwData["GABBUCHDAT"] = DAT;
            try
            {
                SResult = ((VICC_GBMOV)MV).QueryICC_GBMOV(dwData, 3);
                MergeData(SResult, true, true);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        private void PrintCommand(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ITXEXRPT == null)
                {
                    ITXEXRPT = new ITXEXRPT();
                    ITXEXRPT.Root = "C:\\IntexReport";
                    ITXEXRPT.strCompany = app.company;
                    ITXEXRPT.PrintType = "OpenExcel";
                }
                ITXEXRPT.dsSource = SResult;
                //ITXEXRPT.dsSource.Merge(SetEnv);

                ITXEXRPT.DocType = "YGRCPGBMOV";
                ITXEXRPT.STARTD = FROMDATE;
                ITXEXRPT.ENDD = ENDDATE;

                ITXEXRPT.strExcelFile = @"\YGR\YGRGBMOV.xls";
                string filename = ITXEXRPT.WriteExcelReport();
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void FROM_DATE_SelectedDateChanged(object sender, System.EventArgs e)
        {
            try
            {
                //FROMDATE = "";
                FROMDATE = Helpers.Helper.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        private void END_DATE_SelectedDateChanged(object sender, System.EventArgs e)
        {
            try
            {
                //ENDDATE = "";
                ENDDATE = Helpers.Helper.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        public override void OnPARTIEChg(string value)
        {
            base.OnPARTIEChg(value);
        }
    }
}